#ifndef ARTICLEMANAGER_H
#define ARTICLEMANAGER_H

#include "article.h"
#include "articlecreator.h"
#include "articlefetcher.h"
#include "articlelister.h"
#include "articleupdater.h"

#include <QObject>

class ArticleManager : public QObject {
    Q_OBJECT

public:
    explicit ArticleManager(QObject* parent = nullptr);

    // 设置请求模式（同步或异步）
    void setSyncMode(bool sync);

    void createArticle(Article article);
    void updateArticle(Article article);
    void fetchArticleList();
    void fetchArticleById(uint articleID);

signals:
    void articleCreated(bool success, const QString& message);
    void articleUpdated(bool success, const QString& message);
    void articleListFetched(const QList<QJsonObject>& articles);
    void articleFetched(const QJsonObject& article);
    void operationFailed(const QString& error);

private slots:
    void onArticleCreated(bool success, const QString& message);
    void onArticleUpdated(bool success, const QString& message);
    void onArticleListFetched(const QList<QJsonObject>& articles);
    void onArticleFetched(const QJsonObject& article);
    void onFetchFailed(const QString& error);

private:
    ArticleCreator* creator;
    ArticleUpdater* updater;
    ArticleLister* lister;
    ArticleFetcher* fetcher;
};

#endif // ARTICLEMANAGER_H
